/*
 * @Author: wwl 2967796480@qq.com
 * @Date: 2023-08-08 08:58:02
 * @LastEditors: wwl 2967796480@qq.com
 * @LastEditTime: 2023-08-21 10:01:46
 * @FilePath: \ConstantBlueCloud_WEB_USER_DZ1\src\views\userSetting\components\page.tsx
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
import {uSelectWebUserInfo} from '@/api/user'
import {CnBoldP, CnNormalP} from '@/components/text'
import {getUserId} from '@/libs/auth'
import {
  UserSettingItem,
  SystemSettingItem,
  CompanySettingItem,
  CBCSettingItem
} from './userSettingItem'

const UseSettingPage = defineComponent({
  name: 'dataOverview',
  setup() {
    const state = reactive<{
      spinning: boolean
      userInfo: User.Info | null
    }>({
      userInfo: null,
      spinning: false
    })

    function getPageData() {
      const userId = getUserId()
      if (!userId) return
      state.spinning = true
      uSelectWebUserInfo({userId})
        .then(res => {
          console.log(res)
          // 处理数据
          let resData = res.data
          resData.userCode = resData.platFormSubUserCode
          resData.userCompany = resData.platFormSubUserCompany
          resData.userCreateTime = resData.platFormSubUserCreateTime
          resData.userDesc = resData.platFormSubUserDesc
          resData.userEmail = resData.platFormSubUserEmail
          resData.userId = resData.platFormSubUserId
          resData.userLastLogin = resData.platFormSubUserLastLogin
          resData.userName = resData.platFormSubUserName
          resData.userWeichatId = resData.platFormSubUserWeichatId

          state.userInfo = resData
          state.spinning = false
        })
        .catch(() => {
          state.userInfo = null
          state.spinning = false
        })
    }
    onMounted(() => {
      getPageData()
    })
    return () => (
      <div class='pb-24'>
        <CnBoldP class='mt-11 text-20'>个人设置</CnBoldP>

        <CnNormalP class='mt-6 mb-20 text-4xText'>
          在这里设置您的基本资料，公司信息，账号信息，并接收系统通知
        </CnNormalP>
        {state.userInfo ? (
          <div class='grid grid-cols-1 gap-y-20'>
            <UserSettingItem
              userInfo={state.userInfo}
              onFinished={() => getPageData()}
            ></UserSettingItem>

            <SystemSettingItem
              userInfo={state.userInfo}
              onFinished={() => getPageData()}
            ></SystemSettingItem>

            <CompanySettingItem
              userInfo={state.userInfo}
              onFinished={() => getPageData()}
            ></CompanySettingItem>

            <CBCSettingItem
              userInfo={state.userInfo}
              onFinished={() => getPageData()}
            ></CBCSettingItem>
          </div>
        ) : state.spinning ? (
          <a-spin></a-spin>
        ) : null}
      </div>
    )
  }
})

export default UseSettingPage
